/**
 * Created by Administrator on 2019/6/26 0009.
 */
/**
 * Phone-check
 */
var ip;
var machineId;
function check_phone() {
    var re = /^1[3|4|5|8][0-9]\d{8}$/;
    if (!re.test($("#phone").val())) {
        $("#phoneError").html("请输入正确的手机号！");
        $("#phone").addClass('error');
        return false;
    } else {
        $("#phone").removeClass('error');
        $("#phoneError").html("");
        return true;
    }
}

/**
 * Null-check
 */
function check_null(Id) {
    var id = '#' + Id;
    console.log(Id);
    console.log($(id).val());
    if ($(id).val() === '') {
        $(id + 'Error').html("不能为空！");
        $(id).addClass('error');
        return false;
    } else {
        $(id + 'Error').html("");
        $(id).removeClass('error');
        return true;
    }
}

/**
 * Num-check
 */
function check_num(Id) {
    var id = '#' + Id;
    var re = /^[0-9]+$/;
    var value = $(id).val();
    console.log(re.test(value));
    if (!re.test(value)) {
        $(id + 'Error').html("请输入纯数字！");
        return false;
    } else {
        $(id + 'Error').html("");
        return true;
    }
}


//检测占位数为纯数字


function selectType() {
    if ($("#selectType").val() == "") {
        $("#typeError").html("请选择类型");
        $("#shelveType").removeClass('error');
        return false;
    } else {
        $("#typeError").html("");
        $("#shelveType").removeClass('error');
        return true;
    }
}
function checkMachineId() {
    console.log("check.84");

    if (check_null('machineId')) {
        var param = {
            uuid:$("#storageSelect").val(),
            machineId: $("#machineId").val()
        };
        console.log('check.91.param',param);
        var success = function (ret) {
            if (ret === true) {
                $("#machineIdError").html("机台号已存在！");
                console.log('false');
                machineId = false;
            } else {
                $("#machineId").html("");
                machineId =  true;
            }
        };
        ajax('get', '/storage/Machine/checkMachineId', param, success);
        return machineId;
    }
}
function checkSeatNumber() {
    var result;
    var seatNumber = $("#seatNumber").val();
    console.log('check.98.param',seatNumber);
    result = check_num('seatNumber');
    if(seatNumber > 200 || seatNumber <= 0){
        $('#seatNumberError').html("站位数量过多！");
        return false;
    }
    return result;

}


var clickMachine = 0;
//对添加机台时输入的信息进行校验
//todo： 还有具体各个输入框的格式没有校验，如产线格式，以及机器号格式。看之后他们要不要加吧。
function checkMachine(){
    console.log("check.109");

    var ret = false;
    if (clickMachine === 0) {
        clickMachine = 1;
        ret = (check_null('machineId')&&check_null('storageSelect')&&checkMachineId()&&check_null('productLine')&&checkSeatNumber('seatNumber'));
        setTimeout(function () {
            clickMachine = 0;
        }, 1000);
    }
    return ret;
}
